using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.Modules
{
    
    
    public partial class Formater {
        
        private System.Nullable<System.Guid> _forId;
        
        private string _forName;
        
        private string _forDescription;
        
        private FormaterConfigurationCollection _formaterConfigurationCollection;
        
        private ModuleInstanceCollection _moduleInstanceCollection;
        
        private OptionCollection _optionCollection;
        
        public virtual System.Nullable<System.Guid> ForId {
            get {
                return _forId;
            }
            set {
                _forId = value;
            }
        }
        
        public virtual string ForName {
            get {
                return _forName;
            }
            set {
                _forName = value;
            }
        }
        
        public virtual string ForDescription {
            get {
                return _forDescription;
            }
            set {
                _forDescription = value;
            }
        }
        
        public virtual FormaterConfigurationCollection FormaterConfigurationCollection {
            get {
                if ((this._formaterConfigurationCollection == null)) {
                    _formaterConfigurationCollection = FormaterConfiguration.Select_FORMATER_CONFIGURATION_By_FOR_ID(this.ForId);
                }
                return this._formaterConfigurationCollection;
            }
        }
        
        public virtual ModuleInstanceCollection ModuleInstanceCollection {
            get {
                if ((this._moduleInstanceCollection == null)) {
                    _moduleInstanceCollection = ModuleInstance.Select_MODULE_INSTANCE_By_FOR_ID(this.ForId);
                }
                return this._moduleInstanceCollection;
            }
        }
        
        public virtual OptionCollection OptionCollection {
            get {
                if ((this._optionCollection == null)) {
                    _optionCollection = Option.Select_OPTION_By_FOR_ID(this.ForId);
                }
                return this._optionCollection;
            }
        }
        
        private void Clean() {
            this.ForId = null;
            this.ForName = string.Empty;
            this.ForDescription = string.Empty;
            this._formaterConfigurationCollection = null;
            this._moduleInstanceCollection = null;
            this._optionCollection = null;
        }
        
        private void Fill(System.Data.DataRow dr) {
            this.Clean();
            if ((dr["FOR_ID"] != System.DBNull.Value)) {
                this.ForId = ((System.Nullable<System.Guid>)(dr["FOR_ID"]));
            }
            if ((dr["FOR_NAME"] != System.DBNull.Value)) {
                this.ForName = ((string)(dr["FOR_NAME"]));
            }
            if ((dr["FOR_DESCRIPTION"] != System.DBNull.Value)) {
                this.ForDescription = ((string)(dr["FOR_DESCRIPTION"]));
            }
        }
        
        public static FormaterCollection GetAll() {
            IrisGenerator.Dal.Formater dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Formater();
                System.Data.DataSet ds = dbo.FORMATER_Select_All();
                FormaterCollection collection = new FormaterCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Formater obj = new Formater();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static Formater Load(System.Nullable<System.Guid> FOR_ID) {
            IrisGenerator.Dal.Formater dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Formater();
                System.Data.DataSet ds = dbo.FORMATER_Select_One(FOR_ID);
                Formater obj = null;
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        obj = new Formater();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Load() {
            IrisGenerator.Dal.Formater dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Formater();
                System.Data.DataSet ds = dbo.FORMATER_Select_One(this.ForId);
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Insert() {
            IrisGenerator.Dal.Formater dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Formater();
                dbo.FORMATER_Insert(this.ForName, this.ForDescription);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Delete() {
            IrisGenerator.Dal.Formater dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Formater();
                dbo.FORMATER_Delete(this.ForId);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Update() {
            IrisGenerator.Dal.Formater dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Formater();
                dbo.FORMATER_Update(this.ForId, this.ForName, this.ForDescription);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
    }
}
